package com.demo.ping.service.impl

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.springframework.kafka.core.KafkaTemplate
import org.springframework.test.util.ReflectionTestUtils
import static org.mockito.ArgumentMatchers.*
import static org.mockito.Mockito.*

@ExtendWith(MockitoExtension)
class KafkaServiceImplTest {

    @Mock
    KafkaTemplate<String, String> kafkaTemplate

    @InjectMocks
    KafkaServiceImpl kafkaService

    @BeforeEach
    void setUp() {
        ReflectionTestUtils.setField(kafkaService, 'topic', 'log_topic')
    }

    @Test
    void sendMessage_ShouldSendMessageToKafkaTopic() {
        // Arrange
        def key = 'testKey'
        def message = 'testMessage'

        // Act
        kafkaService.sendMessage(key, message)

        // Assert
        verify(kafkaTemplate, times(1)).send(anyString(), anyString(), anyString())
    }
}
